package com.tang.subject.domain.entity;

import com.tang.subject.common.enums.CorrectEnum;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Data
public class SubjectOptionBO {
    /**
     * 题目答案
     */
    private String subjectAnswer;

    /**
     * 答案选项
     */
    private List<SubjectAnswerBO> optionList;

    public void setOptionList(List<SubjectAnswerBO> optionList) {
        this.optionList = optionList;
        if (CollectionUtils.isEmpty(optionList)) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (SubjectAnswerBO subjectAnswerBO : optionList) {
            if (CorrectEnum.RIGHT.code.equals(subjectAnswerBO.getIsCorrect())) {
                sb.append(subjectAnswerBO.getOptionType());
            }
        }
        subjectAnswer = sb.toString();
    }
}
